#pragma once

#include "LogUtil.h"

#include <windows.h>
#include <WinSock.h>
#include <time.h>

static int GetTimeOfDay(struct timeval *tp, void *tzp) {
    time_t clock;
    struct tm tm;
    SYSTEMTIME wtm;
    GetLocalTime(&wtm);
    tm.tm_year = wtm.wYear - 1900;
    tm.tm_mon = wtm.wMonth - 1;
    tm.tm_mday = wtm.wDay;
    tm.tm_hour = wtm.wHour;
    tm.tm_min = wtm.wMinute;
    tm.tm_sec = wtm.wSecond;
    tm.tm_isdst = -1;
    clock = mktime(&tm);
    tp->tv_sec = static_cast<long>(clock);
    tp->tv_usec = wtm.wMilliseconds * 1000;
    return (0);
}

static unsigned long long CurrentTimeMillis(void) {
    struct timeval tv;
    GetTimeOfDay(&tv, nullptr);
    return tv.tv_sec * 1000000ULL + tv.tv_usec;
}

#ifdef DEBUG
#define BEGIN_TIME(tag) unsigned long long time_##tag##_start = CurrentTimeMillis();
#define END_TIME(tag) unsigned long long time_##tag##_end = CurrentTimeMillis();\
        LOGI(L#tag L"time: %.3f ms", ((time_##tag##_end - time_##tag##_start) / 1000.0));
#else
#define __TIC1__(tag)
#define __TOC1__(tag)
#endif // DEBUG

